convert text to Format class (#847)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sun, 30 Jan 2022 16:19:16 +0000 (09:19 -0700)
committerGitHub <noreply@github.com>
Sun, 30 Jan 2022 16:19:16 +0000 (09:19 -0700)
CMakeLists.txt
GPSBabel.pro
text.cc
text.h [new file with mode: 0644]
vecs.h

index 94a9a38c09b863459b9ecbb3074f5373ae7f567f..7dcb4d4a9a6f682e0b9b67639c3ca64548741409 100644 (file)
@@ -265,6 +265,7 @@ set(HEADERS
   subrip.h
   tef_xml.h
   teletype.h
+  text.h
   unicsv.h
   units.h
   vecs.h
index d755cd20593ff2cfa0c3bdadcc2551f936a69861..49faaaf012719d429009dce10ecd85dceb72a0c3 100644 (file)
@@ -252,6 +252,7 @@ HEADERS =  \
   subrip.h \
   tef_xml.h \
   teletype.h \
+  text.h \
   unicsv.h \
   units.h \
   vecs.h \
diff --git a/text.cc b/text.cc
index 143b037f6f960014b19c13678e2a0836b9dff275..9b5e478ca4a905a5d2e678e7396ca700d8289b31 100644 (file)
--- a/text.cc
+++ b/text.cc
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
 
-#include <cstdint>
-#include <ctime>                   // for localtime
+#include "text.h"
 
 #include <QString>                 // for QString, operator!=
-#include <QVector>                 // for QVector
 #include <Qt>                      // for CaseInsensitive
 
-#include "defs.h"
-#include "formspec.h"              // for FsChainFind, kFsGpx
-#include "gbfile.h"                // for gbfprintf, gbfputs, gbfclose, gbfopen, gbfile
+#include <cstdint>                 // for int32_t
+#include <ctime>                   // for localtime, time_t, tm
+
+#include "defs.h"                  // for Waypoint, xfree, geocache_data, pretty_deg_format, rot13, strip_html, xasprintf, CSTR, METERS_TO_FEET, gs_get_cachetype, gs_get_container, mkshort_del_handle, mkshort_from_wpt, mkshort_new_handle, setshort_length, waypt_disp_all, xml_parse_time, utf_string
+#include "formspec.h"              // for FormatSpecificDataList, kFsGpx
+#include "gbfile.h"                // for gbfprintf, gbfputs, gbfclose, gbfopen
 #include "jeeps/gpsmath.h"         // for GPS_Math_WGS84_To_UTM_EN
 #include "src/core/datetime.h"     // for DateTime
-#include "src/core/xmltag.h"       // for xml_findfirst, xml_attribute, xml_tag, fs_xml, xml_findnext
-
-
-static gbfile* file_out;
-static short_handle mkshort_handle;
+#include "src/core/xmltag.h"       // for xml_findfirst, xml_tag, xml_attribute, fs_xml, xml_findnext
 
-static char* suppresssep = nullptr;
-static char* txt_encrypt = nullptr;
-static char* includelogs = nullptr;
-static char* degformat = nullptr;
-static char* altunits = nullptr;
-static char* split_output = nullptr;
-static int waypoint_count;
-static QString output_name;
 
 #define MYNAME "TEXT"
 
-static
-QVector<arglist_t> text_args = {
-  {
-    "nosep", &suppresssep,
-    "Suppress separator lines between waypoints",
-    nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
-  },
-  {
-    "encrypt", &txt_encrypt,
-    "Encrypt hints using ROT13", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
-  },
-  {
-    "logs", &includelogs,
-    "Include groundspeak logs if present", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
-  },
-  {
-    "degformat", &degformat,
-    "Degrees output as 'ddd', 'dmm'(default) or 'dms'", "dmm", ARGTYPE_STRING, ARG_NOMINMAX, nullptr
-  },
-  {
-    "altunits", &altunits,
-    "Units for altitude (f)eet or (m)etres", "m", ARGTYPE_STRING, ARG_NOMINMAX, nullptr
-  },
-  {
-    "splitoutput", &split_output,
-    "Write each waypoint in a separate file", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
-  },
-
-};
-
-
-
-static void
-wr_init(const QString& fname)
+void
+TextFormat::wr_init(const QString& fname)
 {
   waypoint_count = 0;
   output_name = fname;
@@ -91,8 +48,8 @@ wr_init(const QString& fname)
   mkshort_handle = mkshort_new_handle();
 }
 
-static void
-wr_deinit()
+void
+TextFormat::wr_deinit()
 {
   if (!split_output) {
     gbfclose(file_out);
@@ -101,8 +58,8 @@ wr_deinit()
   output_name.clear();
 }
 
-static void
-text_disp(const Waypoint* wpt)
+void
+TextFormat::text_disp(const Waypoint* wpt)
 {
   int32_t utmz;
   double utme, utmn;
@@ -248,30 +205,15 @@ text_disp(const Waypoint* wpt)
   }
 }
 
-static void
-data_write()
+void
+TextFormat::write()
 {
   if (! suppresssep && !split_output) {
     gbfprintf(file_out, "-----------------------------------------------------------------------------\n");
   }
   setshort_length(mkshort_handle, 6);
-  waypt_disp_all(text_disp);
+  auto text_disp_lambda = [this](const Waypoint* waypointp)->void {
+    text_disp(waypointp);
+  };
+  waypt_disp_all(text_disp_lambda);
 }
-
-
-ff_vecs_t text_vecs = {
-  ff_type_file,
-  { ff_cap_write, ff_cap_none, ff_cap_none},
-  nullptr,
-  wr_init,
-  nullptr,
-  wr_deinit,
-  nullptr,
-  data_write,
-  nullptr,
-  &text_args,
-  CET_CHARSET_ASCII, 0 /* CET-REVIEW */
-  , NULL_POS_OPS,
-  nullptr
-
-};
diff --git a/text.h b/text.h
new file mode 100644 (file)
index 0000000..6bfce4f
--- /dev/null
+++ b/text.h
@@ -0,0 +1,113 @@
+/*
+    Output only format for Human Readable formats.
+
+    Copyright (C) 2004 Scott Brynen, scott (at) brynen.com
+    Copyright (C) 2002-2014 Robert Lipe, robertlipe+source@gpsbabel.org
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*/
+#ifndef TEXT_H_INCLUDED_
+#define TEXT_H_INCLUDED_
+
+#include <QString>   // for QString
+#include <QVector>   // for QVector
+
+#include "defs.h"    // for arglist_t, ff_cap, ARG_NOMINMAX, ARGTYPE_BOOL, ARGTYPE_STRING, ff_cap_none, CET_CHARSET_ASCII, Waypoint, ff_cap_write, ff_type, ff_type_file, short_handle
+#include "format.h"  // for Format
+#include "gbfile.h"  // for gbfile
+
+
+class TextFormat : public Format
+{
+public:
+  QVector<arglist_t>* get_args() override
+  {
+    return &text_args;
+  }
+
+  ff_type get_type() const override
+  {
+    return ff_type_file;
+  }
+
+  QVector<ff_cap> get_cap() const override
+  {
+    /*          waypoints,      tracks,      routes */
+    return { ff_cap_write, ff_cap_none, ff_cap_none};
+  }
+
+  QString get_encode() const override
+  {
+    return CET_CHARSET_ASCII;
+  }
+
+  int get_fixed_encode() const override
+  {
+    return 0;
+  }
+
+  void wr_init(const QString& fname) override;
+  void write() override;
+  void wr_deinit() override;
+
+private:
+  /* Member Functions */
+
+  void text_disp(const Waypoint* wpt);
+
+  /* Data Members */
+
+  gbfile* file_out{};
+  short_handle mkshort_handle{};
+
+  char* suppresssep = nullptr;
+  char* txt_encrypt = nullptr;
+  char* includelogs = nullptr;
+  char* degformat = nullptr;
+  char* altunits = nullptr;
+  char* split_output = nullptr;
+  int waypoint_count{};
+  QString output_name;
+
+  QVector<arglist_t> text_args = {
+    {
+      "nosep", &suppresssep,
+      "Suppress separator lines between waypoints",
+      nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
+    },
+    {
+      "encrypt", &txt_encrypt,
+      "Encrypt hints using ROT13", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
+    },
+    {
+      "logs", &includelogs,
+      "Include groundspeak logs if present", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
+    },
+    {
+      "degformat", &degformat,
+      "Degrees output as 'ddd', 'dmm'(default) or 'dms'", "dmm", ARGTYPE_STRING, ARG_NOMINMAX, nullptr
+    },
+    {
+      "altunits", &altunits,
+      "Units for altitude (f)eet or (m)etres", "m", ARGTYPE_STRING, ARG_NOMINMAX, nullptr
+    },
+    {
+      "splitoutput", &split_output,
+      "Write each waypoint in a separate file", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
+    }
+
+  };
+};
+#endif // TEXT_H_INCLUDED_
diff --git a/vecs.h b/vecs.h
index 0a25e21a75f20c95235ab0aa09b750c26c0ca394..4f7611c7e98b6261743f6dba7311087d2a2b02a5 100644 (file)
--- a/vecs.h
+++ b/vecs.h
@@ -56,6 +56,7 @@
 #include "subrip.h"
 #include "tef_xml.h"
 #include "teletype.h"
+#include "text.h"
 #include "unicsv.h"
 #include "wintec_tes.h"
 #include "xcsv.h"
@@ -75,7 +76,6 @@ extern ff_vecs_t tpo3_vecs;
 extern ff_vecs_t easygps_vecs;
 extern ff_vecs_t saroute_vecs;
 extern ff_vecs_t gpl_vecs;
-extern ff_vecs_t text_vecs;
 extern ff_vecs_t igc_vecs;
 extern ff_vecs_t brauniger_iq_vecs;
 extern ff_vecs_t mtk_vecs;
@@ -249,7 +249,7 @@ private:
   ShapeFormat shape_fmt;
 #endif
   LegacyFormat gpl_fmt {gpl_vecs};
-  LegacyFormat text_fmt {text_vecs};
+  TextFormat text_fmt;
   HtmlFormat html_fmt;
   LegacyFormat igc_fmt {igc_vecs};
   LegacyFormat brauniger_iq_fmt {brauniger_iq_vecs};